﻿using Rong.EasyExcel.Attributes;
using Simple.Common.Extensions;
using Simple.Repository.Models.Attendance;

namespace Simple.Services;

public class StaffAttendanceRuleOutputModel : ModelBase
{
    /// <summary>
    /// 主键Id
    /// </summary>
    public Guid? Id { get; set; } = null;

    /// <summary>
    /// 考勤组名称
    /// </summary>
    [Required(ErrorMessage = "请填写考勤组名称")]
    [MaxLength(20, ErrorMessage = "班级名称长度不能超过20个字符")]
    public string Name { get; set; } = "";

    /// <summary>
    /// 开始时刻（24小时制）
    /// </summary>
    [Required(ErrorMessage = "请填写考勤开始时间")]
    public string StartTime { get; set; } = "";

    /// <summary>
    /// 结束时刻（24小时制）
    /// </summary>
    [Required(ErrorMessage = "请填写考勤结束时间")]
    public string EndTime { get; set; } = "";

    /// <summary>
    /// 法定节假日是否自动排休
    /// </summary>
    public bool IsExcludingLegalHolidays { get; set; } = true;

    /// <summary>
    /// 考勤组人员
    /// </summary>
    [Required(ErrorMessage = "请选择考勤组人员")]
    public List<StaffAttendanceUserOutputModel> Users { get; set; } = null;

    /// <summary>
    /// 考勤周期
    /// </summary>
    [Required(ErrorMessage = "请选择考勤周期")]
    public List<StaffAttendanceCycleOutputModel> CycleSettings { get; set; } = null;

    public override void ConfigureMapper(Profile profile)
    {
        profile.CreateMap<StaffAttendanceRule, StaffAttendanceRuleOutputModel>();

        profile.CreateMap<StaffAttendanceRuleOutputModel, StaffAttendanceRule>();
    }
}

public class StaffAttendanceUserOutputModel : ModelBase
{
    /// <summary>
    /// 人员Id
    /// </summary>
    public Guid UserId { get; set; }

    /// <summary>
    /// 人员姓名
    /// </summary>
    public string UserName { get; set; } = "";

    public override void ConfigureMapper(Profile profile)
    {
        profile.CreateMap<StaffAttendanceUser, StaffAttendanceUserOutputModel>();

        profile.CreateMap<StaffAttendanceUserOutputModel, StaffAttendanceUser>();
    }
}


public class StaffAttendanceCycleOutputModel : ModelBase
{
    /// <summary>
    /// 工作日名称
    /// </summary>
    public string Name { get; set; } = "";

    /// <summary>
    /// 考勤日(PeriodType)
    /// </summary>
    public PeriodType PeriodType { get; set; }

    public override void ConfigureMapper(Profile profile)
    {
        profile.CreateMap<StaffAttendanceCycle, StaffAttendanceCycleOutputModel>()
            .ForMember(c => c.PeriodType, option => option.MapFrom(p => (PeriodType)p.PeriodType));

        profile.CreateMap<StaffAttendanceCycleOutputModel, StaffAttendanceCycle>()
            .ForMember(c => c.PeriodType, option => option.MapFrom(p => p.PeriodType.GetHashCode()))
            .ForMember(c => c.Name, option => option.MapFrom(p => p.PeriodType.GetEnumDescription()));
    }
}




[HeaderStyle(ColumnAutoSize = true)] // 自动列宽
public class AttendanceRecordExcelModel
{

    /// <summary>
    /// 编号
    /// </summary>
    [Display(Name = "编号")]
    public string Code { get; set; } = "";

    /// <summary>
    /// 姓名
    /// </summary>
    [Display(Name = "姓名")]
    public string Name { get; set; } = "";

    /// <summary>
    /// 日期
    /// </summary>
    [Display(Name = "日期")]
    public string? Date { get; set; }

    /// <summary>
    /// 上午
    /// </summary>
    [Display(Name = "上午")]
    public string? AM { get; set; }

    /// <summary>
    /// 下午
    /// </summary>
    [Display(Name = "下午")]
    public string? PM { get; set; }

}
